//
//  LLGVisitorTableViewController.swift
//  Weibo30LLG
//
//  Created by 李龙 on 16/8/8.
//  Copyright © 2016年 lilong. All rights reserved.
//

import UIKit

class LLGVisitorTableViewController: UITableViewController {

    //判断是否登录
    var isLogin: Bool = LLGUserAccountViewModel.sharedUserAccount.isLogin
    
    var visitorView: LLGVisitorView?

    // MARK: --加载视图
    override func loadView() {
        if isLogin {
        
            super.loadView()
        } else {
        
            visitorView = LLGVisitorView()
            
            visitorView?.loginClosure = { [weak self] in
                
                self?.requestOAuthVC()
            }
            
            view = visitorView
            
            setupNav()
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        
    }
    
    // MARK: --添加导航栏item
    private func setupNav() {
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: "registerButton")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: "loginButton")
        
    }
    

    // MARK: --点击事件
    @objc private func registerButton() {
    
        print("注册")
        
        requestOAuthVC()
    }
    @objc private func loginButton() {
    
        print("登录")
        
        requestOAuthVC()
    }
    
    // MARK: --第三方登录
    private func requestOAuthVC() {
    
        print("登录第三方")
        
        let oAuthVC: LLGOAuthViewController = LLGOAuthViewController()
        
        let nav = UINavigationController(rootViewController: oAuthVC)
        
        navigationController?.presentViewController(nav, animated: true, completion: nil)
        
        
    }

}
